<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BookingHotelcontroller
 *
 * @author fabiano
 */

require_once SITE_ROOT_PATH."/_lib/classes/class.tree.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.hotel_supplier_low.php";
require_once SITE_ROOT_PATH."/_lib/classes/model/LowSupplier.php";

class BookingHotelController {
    
    private $supplier;  
     
    public function __construct($code) {
       // need to read the file with the supplier configuration 
        $suppliersConfigFile = simplexml_load_file(SUPPLIERS_CONFIG_FILE, 'SimpleXMLElement', LIBXML_NOCDATA);        
        if ($suppliersConfigFile) {
            foreach ($suppliersConfigFile as $supplierConfig) {                
                $codeSupplier = (string)$supplierConfig["code"];
                if ( $code == $codeSupplier) {
                    $supplier = new LowSupplier($supplierConfig);        
                    $this->supplier = $supplier; 
                }                
            }
        }        
    }
    
    public function executeActionBooking($params){       
        $this->supplier->buildBookingXML($params);
        $xml = $this->supplier->sendBookingRequest();   
        $result = $this->supplier->parseXmlBookingResult($xml);        
        $result["supplier_code"] = $params["supplier_code"];      
        return $result;                
    }
}

?>
